$(function () {
    let id = localStorage.getItem("newsId");
    findNewsClassify();
    selectNewsById(id);
})

//查询一条数据库
function selectNewsById(id) {
    let data = myAjax('/back/news/updateNews',{id: id},'get');
    setData(data.newsModel);
}

function setData(data) {
    $("#newsClassify").val(data.type);
    $("#title").val(data.title);
    $("#content").val(data.content);
    $("#contentall").val(data.contentall);
    $("#newsTime").val(data.time);
    $("#author").val(data.author);
}

function findNewsClassify() {
    let data = myAjax('/back/news/findNewsClassify','','get');
    data = data.model;
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += ' <option value="' + data[i].id + '">' + data[i].classify + '</option>';
    }
    ;
    $("#newsClassify").html(html);
}

//更新数据===================================================
function updateNews() {
    let newsid = localStorage.getItem("newsId");
    updateNewsById(newsid);
}

function updateNewsById(id) {
    let data1 = {
        id:id,
        newsClassify:$("#newsClassify").val(),
        title:$("#title").val(),
        content:$("#content").val(),
        contentall:$("#contentall").val(),
        newsTime:$("#newsTime").val(),
        author:$("#author").val(),
    };
    let data = myAjax('/back/news/updateNews',data1,'post');
    if (data.result==1){
        alert("更新成功");
    }else {
        alert("更新失败");
    };

}

//返回上一页面。。。。。。。。
function back() {
    $("#right").load("/back/html/news/newsManage.html");
}
